package com.example.Opd_ISF_Android_Application.controller;

import android.content.Context;
import android.content.Intent;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.widget.Toast;

/**
 * Created with IntelliJ IDEA.
 * User: Dell
 * Date: 26/03/13
 * Time: 19:16
 * To change this template use File | Settings | File Templates.
 */
public class LoginManager {

    /* Intermediar tussen Website & App */

    public static boolean authenticateLogin(String username, String password) {
        /*
         * This method will handle the login of a user in full based on the data from the parameters
         * The login activity should call this method when login is pressed. If true is returned the
         * activity in which he can post a score will be show, if not a toast or dialog should be shown
         * warning the user. It should also open a session or do whatever necessary to establish the connection.
        */
        return true;
    }

    public static void logout() {
        /*
         * This method will handle the logout of a user from the server
        */
    }

    /*
       * This method checks if the user has an internet connection present. It is called in the splash activity class
      */
    public static boolean isOnline(Context context) {
        ConnectivityManager cm =
                (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
        NetworkInfo netInfo = cm.getActiveNetworkInfo();
        // Check connection info
        if (netInfo != null && netInfo.isConnectedOrConnecting()) {
            return true;
        } else {
            // Open wifi settings if no internet was found
            context.startActivity(new Intent(android.provider.Settings.ACTION_WIFI_SETTINGS));
            try {
                // Show message stating an internet connection is needed, Thread.sleep(xxxx) is used for UX, softer transition
                Toast msg = Toast.makeText(context, "Internet connection is required for this application!", 10000);
                Thread.sleep(700);
                msg.show();
            } catch (InterruptedException e) {
                e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
            }
            return false;
        }
    }
}
